package net.lateeye.search;

import java.util.LinkedList;

import net.lateeye.util.ExpressionHandler;

/**
 * Not used by any other files. Only for testing codes.
 * 
 * @author Isao Isaac Saito <130s@lateeye.net>
 * 
 */
public class ProvingGround extends AbsSearchResultPageTextProcessor
{

	public static void main(String[] args)
	{
		ProvingGround p = new ProvingGround();
	}

	public ProvingGround()
	{
		this.proveRemoveHtmlTag();
	}

	void proveRemoveHtmlTag()
	{
		String[] s = {
				"2004 The <em>Guenther House</em>/<em>San Antonio</em>",
				"<em>San Antonio</em> River Mill Store - Bring home a little history from <b>...</b>",
				"Restaurant Menu - The <em>Guenther House</em>",
				"Printable Menu - The <em>Guenther House</em>",
				"<em>Guenther House</em>, <em>San Antonio</em>,  Texas - Restaurants - VirtualTourist",
				"The <em>Guenther House</em>, <em>San Antonio</em> - Restaurant Reviews - TripAdvisor",
				"The <em>Guenther House</em> - <em>San Antonio</em>, TX, 78204 - Citysearch",
				"The <em>Guenther House</em> - (210) 775-2297 - 205 E Guenther <em>St</em> - <em>San</em> <b>...</b>",
				"The <em>Guenther House</em> Restaurant, Museum, <em>Gift</em> Shop, Banquet Facility",
				"<em>Guenther House</em> - Southtown - <em>San Antonio</em> | Urbanspoon" };
		for (String title : s) {
			ExpressionHandler.removeHtmlTagsSimply(title);
		}
	}

	void proveIndexof()
	{
		String htmSample = "<div>\n<div id=resultStats>About 17,300 results<nobr> (0.12\nseconds)&nbsp;</nobr></div>";
		String findkey = "<div>";
		String prefix_targetString = "<div id=resultStats>About ";
		String suffix_targetString = " results<nobr> (";
		int startPos = 0;
		startPos = htmSample.indexOf(findkey, startPos);
		int prefixStartPos = htmSample.indexOf(prefix_targetString, startPos)
				+ prefix_targetString.length();// + 1;
		int endPos = htmSample.indexOf(suffix_targetString, prefixStartPos); // doubleQuote
		System.out.println(endPos);
	}

	/**
	 * Lesson: Neither null nor String "" can't be parsed w/NumFormatException
	 */
	void proveParseInt()
	{
		// String nullStr = null;
		String nullStr = "";
		System.out.println(Integer.parseInt(nullStr));
	}

	void proveExtractResultSize()
	{
		String htm = "<div>\n<div id=resultStats>About 26,000 results<nobr> (0.24 seconds)&nbsp;</nobr></div>";
		long answer = -1;
		String findkey = "<div>";
		String prefix_targetString = "<div id=resultStats>About ";
		String suffix_targetString = " results<nobr> (";
		LinkedList<String> results = super.extractStringList(htm,
				prefix_targetString, findkey, suffix_targetString);
		String size = null;
		if (0 < results.size()) {
			size = results.get(0).replaceAll(",", "");
			// TODO need to apply Regex in the future
			size = size.replaceAll(">", "");
			answer = Long.parseLong(size);
		}
		// return answer;
		System.out.println(answer);
	}

	void proveStringNull()
	{
		String a = "a";
		String b = null;
		String c = "c";
		System.out.println(a + b + c);

		StringBuffer sb = new StringBuffer();
		System.out.println(sb.append(a).append(b).append(c));
	}

	void proveReplace()
	{
		String s = "AnullGogo";
		System.out.println(s.replaceAll("null", ""));
	}

	@Override
	protected String createResult(String queryStr, int orderInResults,
			String docUrl, String docTitle, String urlDomain, String summary)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String extractDocTitle(String htmlbody_searchResult)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String extractDocUrl(String htmlbody_searchResult)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected long extractEstimatedSize(String htmlbody_searchResult)
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	protected SearchResult extractOtherMetadata(String result_str,
			SearchResult result_map)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected LinkedList<String> extractResults(String htmlbody_searchResult)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String extractSummary(String htmlbody_searchResult)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected AbsResultSet instantiateResultSet()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected SearchResult instantiateSearchResult()
	{
		// TODO Auto-generated method stub
		return null;
	}
}
